//// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
//package com.linqingying.gitcode.pullrequest.action
//
//import com.intellij.icons.AllIcons
//import com.intellij.notification.Notification
//import com.intellij.notification.NotificationAction
//import com.intellij.openapi.actionSystem.ActionPlaces
//import com.intellij.openapi.actionSystem.ActionUpdateThread
//import com.intellij.openapi.actionSystem.AnActionEvent
//import com.intellij.openapi.components.service
//import com.intellij.openapi.project.DumbAwareAction
//import com.intellij.openapi.project.Project
//import com.linqingying.gitcode.authentication.accounts.GitCodeAccount
//import com.linqingying.gitcode.i18n.GitCodeBundle
//import com.linqingying.gitcode.icons.GitCodeIcons
//import com.linqingying.gitcode.pullrequest.ui.toolwindow.model.GCPRToolWindowViewModel
//import com.linqingying.gitcode.util.GCGitRepositoryMapping
//
//internal class GCPRCreatePullRequestAction : DumbAwareAction() {
//  override fun getActionUpdateThread(): ActionUpdateThread {
//    return ActionUpdateThread.EDT
//  }
//
//  override fun update(e: AnActionEvent) {
//    with(e) {
//      val vm = project?.service<GCPRToolWindowViewModel>()
//      val twAvailable = project != null && vm != null && vm.isAvailable.value
//      val twInitialized = project != null && vm != null && vm.projectVm.value != null
//
//      if (place == ActionPlaces.TOOLWINDOW_TITLE) {
//        presentation.isEnabledAndVisible = twInitialized
//        presentation.icon = AllIcons.General.Add
//      }
//      else {
//        presentation.isEnabledAndVisible = twAvailable
//        presentation.icon =   GitCodeIcons.GIT_CODE_ICON
//      }
//    }
//  }
//
//  override fun actionPerformed(e: AnActionEvent) = tryToCreatePullRequest(e)
//}
//
//// NOTE: no need to register in plugin.xml
//internal class GCPRCreatePullRequestNotificationAction(
//  private val project: Project,
//  private val projectMapping: GCGitRepositoryMapping,
//  private val account: GitCodeAccount
//) : NotificationAction(
//  GitCodeBundle.message("pull.request.notification.create.action")
//) {
//  override fun actionPerformed(e: AnActionEvent, notification: Notification) {
//    val twVm = project.service<GCPRToolWindowViewModel>()
//    val selectorVm = twVm.selectorVm
//    selectorVm.selectRepoAndAccount(projectMapping, account)
//    selectorVm.submitSelection()
//
//    tryToCreatePullRequest(e)
//  }
//}
//
//private fun tryToCreatePullRequest(e: AnActionEvent) {
//  return e.project!!.service<GCPRToolWindowViewModel>().activateAndAwaitProject {
//    createPullRequest()
//  }
//}
